package cn.webrx;

import org.jsoup.Jsoup;

import javax.swing.*;
import java.io.IOException;
import java.util.Scanner;
import java.util.regex.Pattern;

public class Dict {
    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);

        //String w = sc.nextLine();
        String w  = JOptionPane.showInputDialog("请输入词汇：");
        //so.com
        //String u = "https://www.so.com/s?q=" + w;
        //String t = Jsoup.connect(u).get().select("div[class=mh-translation]").get(0).text();

        //bing
        String u = "https://cn.bing.com/dict/search?q=" + w;
        String t = Jsoup.connect(u).get().select("span[class=def b_regtxt]").get(0).text();

        //String u = String.format("https://youdao.com/result?word=%s&lang=en",w);
        //String t = Jsoup.connect(u).get().select("div[class=word-exp_tran grey]").get(0).text();

        String type = "a[class=point]";
        if(w.matches("[a-zA-z ]+")){
            type = "span[class=trans]";
        }
        //String t = Jsoup.connect(u).get().select(type).get(0).toString();

        //Pattern p = Pattern.compile(".*>(.*)<.*");
        //System.out.println(t.replaceAll(p.toString(),"$1"));

        //String t = Jsoup.connect(u).get().select(type).get(0).text();
        System.out.println(t);
        JOptionPane.showMessageDialog(null,t);
    }
}
